package com.test.multithread.springBean.FactoryBeanTest;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;

public class BeanPostProcessorApp implements BeanPostProcessor {
 
    /**
     * 如果打印结果出现该字符串，说明进行了初始化
     */
    private BeanPostProcessorApp(){
        System.out.println("BeanPostProcessorApp.BeanPostProcessorApp()");
    }
 
    /**
     *
     */
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        if(bean instanceof App){
            ((App) bean).setSays("Before: BeanPostProcessorApp");
            System.out.println("BeanPostProcessorApp.postProcessBeforeInitialization()");
        }
        return bean;
    }
 
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if(bean instanceof App){
            ((App) bean).setSays("After: BeanPostProcessorApp");
            System.out.println("BeanPostProcessorApp.postProcessAfterInitialization()");
        }
        return bean;
    }
}